func timeRequiredToBuy(tickets []int, k int) int {
	res := 0
	ticket := tickets[k]
	for i, v := range tickets {
		if i <= k {
			res += min(ticket, v)
		} else {
			res += min(ticket-1, v)
		}
	}
	return res
}